package cn.topevery.garden.dal.logic;

import cn.topevery.garden.dal.dao.SampleFileDao;
import cn.topevery.garden.dal.dao.ScheduleFileDao;
import cn.topevery.garden.entity.po.SampleFile;
import cn.topevery.garden.entity.po.ScheduleFile;
import cn.topevery.garden.entity.query.ScheduleFileQuery;
import cn.topevery.garden.entity.vo.ScheduleFileVO;
import cn.topevery.garden.framework.base.BaseLogic;
import hw.topevery.framework.db.base.BaseEntityDao;
import hw.topevery.framework.db.entity.DataPager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 
 *
 * @author code-generate
 * @date 2022-01-24
 */
@Service
public class ScheduleFileLogic extends BaseLogic<ScheduleFile> {
    @Autowired
    ScheduleFileDao scheduleFileDao;
    @Autowired
    SampleFileDao sampleFileDao;

    @Override
    public BaseEntityDao<ScheduleFile, Integer> getDao() {
        return scheduleFileDao;
    }

    

    /**
     * 获取列表
     *
     * @param query
     */
    public DataPager<ScheduleFileVO> listPage(ScheduleFileQuery query) {
        return scheduleFileDao.listPage(query);
    }

    /**
     * 根据自增id批量删除
     *
     * @param ids
     */
    public void deleteBatchById(String userId,Integer[] ids) {
        scheduleFileDao.delete(userId, ids);
    }

    /**
     * 根据自增id保存或者更新
     *
     * @param scheduleFile 实体
     */
    public void saveOrUpdate(String userId, ScheduleFile scheduleFile){
        scheduleFileDao.saveOrUpdate(userId,scheduleFile);
    }

    /**
         * 根据自定义列值来获取对象
         */
    public ScheduleFile getEntityByColumn(String key, String value) {
        return scheduleFileDao.getEntityByColumn(key, value);
    }

    public List<ScheduleFile> getListByPid(Integer id) {
        return scheduleFileDao.getListByPid(id);
    }

    public void saveOrUpdate(String userId, Integer id, List<ScheduleFile> fileList) {
        if (id != null) {
            scheduleFileDao.deleteById(id);
        }
        for (ScheduleFile scheduleFile : fileList) {
            scheduleFile.setGuidId(id.toString());
            scheduleFileDao.saveOrUpdate(userId, scheduleFile);
        }
    }

    public void deleteBatchByGuid(Integer userId, Integer[] ids) {
        scheduleFileDao.deleteBatchByGuid(userId, ids);
    }

    public void saveSampleFile(String userId, Integer id, List<SampleFile> sampleFileList) {
        if (id != null) {
            sampleFileDao.deleteById(id);
        }
        for (SampleFile sampleFile : sampleFileList) {
            sampleFile.setMainId(id);
            sampleFileDao.saveOrUpdate(userId, sampleFile);
        }
    }
}
